﻿#ifndef DEIVCEATTRIBUTES_H
#define DEIVCEATTRIBUTES_H

#include <QSharedPointer>
#include <QString>

#define STR_LevelMin QStringLiteral("LevelMin")                                       //最小电平
#define STR_LevelMax QStringLiteral("LevelMax")                                       //最大电平
#define STR_InputLevelMax QStringLiteral("InputLevelMax")                             //输入电平最大值
#define STR_CouplingConstant QStringLiteral("CouplingConstant")                       //耦合常量
#define STR_CouplingTable QStringLiteral("CouplingTable")                             //耦合表
#define STR_FWDCouplingTable QStringLiteral("FWDCouplingTable")                       //正向耦合表
#define STR_REVCouplingTable QStringLiteral("REVCouplingTable")                       //反向耦合表
#define STR_Channel QStringLiteral("Channel")                                         //通道
#define STR_HFactors QStringLiteral("HFactors")                                       //天线因子 水平
#define STR_VFactors QStringLiteral("VFactors")                                       //天线因子 垂直
#define STR_AttenuatorConstant QStringLiteral("AttenuatorConstant")                   //衰减常量
#define STR_AttenuatorTable QStringLiteral("AttenuatorTable")                         //衰减表
#define STR_CorrectionTableXYZ QStringLiteral("CorrectionTableXYZ")                   //场强探头xyz修正表
#define STR_TransferCharacteristicTable QStringLiteral("TransferCharacteristicTable") //电流注入探头传输属性
#define STR_VFactors QStringLiteral("VFactors")

#define STR_NO_DEVICE QStringLiteral("No Device")
#define STR_NO_TABLE QStringLiteral("No Table")
#define STR_DEVICE_TYPE_SignalGenerators QStringLiteral("SignalGenerators")
#define STR_DEVICE_TYPE_PowerAmplifiers QStringLiteral("PowerAmplifiers")
#define STR_DEVICE_TYPE_PowerMeters QStringLiteral("PowerMeters")
#define STR_DEVICE_TYPE_Receivers QStringLiteral("Receivers")
#define STR_DEVICE_TYPE_SpectrumAnalyzers QStringLiteral("SpectrumAnalyzers")
#define STR_DEVICE_TYPE_SwitchUnits QStringLiteral("SwitchUnits")
#define STR_DEVICE_TYPE_FieldProbes QStringLiteral("FieldProbes")
#define STR_DEVICE_TYPE_GeneralAntenna QStringLiteral("GeneralAntenna")
#define STR_DEVICE_TYPE_GeneralCurrentInjectionProbe QStringLiteral("GeneralCurrentInjectionProbe")

#define STR_TABNAME_TMP_SYMBOL QStringLiteral("(*)")

#define STR_AxisType_LIN QStringLiteral("LIN");
#define STR_AxisType_LOG QStringLiteral("LOG");

#define STR_UNIT_GHZ QStringLiteral("GHz")
#define STR_UNIT_MHZ QStringLiteral("MHz")
#define STR_UNIT_KHZ QStringLiteral("kHz")
#define STR_UNIT_HZ QStringLiteral("Hz")

#define STR_UNIT_VM QStringLiteral("V/m")
#define STR_UNIT_DBUA QStringLiteral("dB\u03BCA")
#define STR_UNIT_DBUV QStringLiteral("dB\u03BCV")
#define STR_UNIT_MA QStringLiteral("mA")
#define STR_UNIT_W QStringLiteral("W")

#define STR_UNIT_DB QStringLiteral("dB")
#define STR_UNIT_DBM QStringLiteral("dBm")

enum DeviceRole {
    Undefined = -1,
    SignalGenerator = 0x0,
    Amplifier,
    AntennaRadiates,              //辐射天线
    AntennaReceives,              //接收天线
    CurrentInjectionProbeInput,   //电流注入探头输入端
    CurrentInjectionProbeMonitor, //电流注入探头监测端
    FieldProbe,                   //场强探头
    PowerMeterForward,            //正向功率计
    PowerMeterReverse,            //反向功率计
    PowerMeterMonitor,            //监测功率计
    Connector_SIG2PA,             //连接器（衰减器） 信号源-功放
    Connector_FWD2PM,             //连接器（衰减器） 正向功率-功率计
    Connector_REV2PM,             //连接器（衰减器） 反向功率-功率计
    Connector_PA2Transducers,     //连接器（衰减器） 功放-换能器
    Connector_Transducers2PM,     //连接器（衰减器） 换能器-功率计
    Receiver,
    SpectrumAnalyzer

};

enum class DeviceType {
    Undefined = -1,
    SignalGenerator,
    Amplifier,
    Antenna,
    CurrentInjectionProbe, //电流探头
    FieldProbe,            //场强探头
    PowerMeter,            //功率计
    Connector,             //连接器
    Receiver,
    SpectrumAnalyzer,
    SwitchUnits
};

enum DeviceStatus {
    Connected = 0, //连接
    DisConnect,    //断开
    Abnormal,      //读写失败或异常
};

//设备测试时状态，显示于主界面左下角
struct DeviceMeasureStatus {
    DeviceRole role;
    DeviceStatus stat;
};

enum DeviceInterfaceType {
    tmp = 0x0,
    LAN,
    COM,
    VISA
};

//通用属性
struct GeneralAttributes {
    int ID = 0;
    DeviceType type;                                              //类型
    QString Model = STR_NO_DEVICE;                                //设备型号
    QString LibraryPath = "";                                     //文件名
    DeviceInterfaceType InterfaceType = DeviceInterfaceType::tmp; //接口类型
    QString InterfaceAddr = "TCPIP0::127.0.0.1::5025::SOCKET";    //接口地址
};

class DeviceConfigBase
{
public:
    virtual ~DeviceConfigBase() = default;
    GeneralAttributes gAttributes;
    //可以把type()等虚函数也移到这里
    DeviceType type() const { return gAttributes.type; }
};
using DeviceConfigBasePtr = QSharedPointer<DeviceConfigBase>;

struct GeneratorConfig : public DeviceConfigBase {
    double LevelMin = -100; //最小电平，单位（dBm）
    double LevelMax = -30;  //最大电平，单位（dBm）

    double Modulation_Frequency = 0;  //调制属性: 频率
    double Modulation_Depth = 0;      //调制属性: 深度
    double Modulation_Deviation = 0;  //调制属性: 频偏
    double Modulation_PulseWidth = 0; //调制属性: 脉宽
};
using GeneratorConfigPtr = QSharedPointer<GeneratorConfig>;

struct AmplifierConfig : public DeviceConfigBase {
    double InputLevelMax = -30;     //最大输入电平值，单位（dBm）
    int CouplerType = 0;            //定向耦合方式 0：标准  1：通过文件
    double CouplerValue = 0;        //定向耦合度值
    int CouplerTableFWDTableID = 0; //正向耦合度表格id  AttTableList
    int CouplerTableREVTableID = 0; //反向耦合度表格id  AttTableList
};
using AmplifierConfigPtr = QSharedPointer<AmplifierConfig>;

struct PowerMeterConfig : public DeviceConfigBase {
    QString DeviceChannel = ""; //已选通道
};
using PowerMeterConfigPtr = QSharedPointer<PowerMeterConfig>;

struct AntennaConfig : public DeviceConfigBase {
    int HFactorsTableID = 0; //垂直天线因子表id  TransducerTableList
    int VFactorsTableID = 0; //垂直天线因子表id  TransducerTableList
    int isVisible = 0;
};
using AntennaConfigPtr = QSharedPointer<AntennaConfig>;

struct FieldProbesConfig : public DeviceConfigBase {
    int CorrectionXYZTableID; //修正XYZ表id  AttTableList
    int isVisible = 0;
};
using FieldProbesConfigPtr = QSharedPointer<FieldProbesConfig>;

struct SpectrumAnalyzerConfig : public DeviceConfigBase {
};
using SpectrumAnalyzerConfigPtr = QSharedPointer<SpectrumAnalyzerConfig>;

struct ReceiverConfig : public DeviceConfigBase {
};
using ReceiverConfigPtr = QSharedPointer<ReceiverConfig>;

struct CurrentInjectionProbeConfig : public DeviceConfigBase {
    int TransducerTableID = 0; //电流注入探头传输属性表id  TransducerTableList
};
using CurrentInjectionProbeConfigPtr = QSharedPointer<CurrentInjectionProbeConfig>;

//连接器，可以是衰减器或开关
struct ConnectorConfig : public DeviceConfigBase {
    int ValueType = 0;   //衰减值类型：0 恒量 / 1 表格
    double AttValue = 0; //固定值；单位 dB
    int AttTableID = 0;  //表格名  AttTableList

    int switchPath = 1;
    int switchChannel = 0;
};
using ConnectorConfigPtr = QSharedPointer<ConnectorConfig>;

#endif // DEIVCEATTRIBUTES_H
